// 用户模块，有自己的state、reducer、actions、actionType
export const initState = {
  info: {
    age: 18,
    name: 'Tony'
  }
}

const actionType = {
  CHNAGEAGE: 'CHANGEAGE',
  CHNAGENAME: 'CHNAGENAME'
}

export const actions = {
  changeAge: (age)=>({type: actionType.CHNAGEAGE, age}),
  changeName: (name)=>({type: actionType.CHNAGENAME, name})
}

const userReducer = (state=initState, action)=>{
  switch (action.type) {
    case actionType.CHNAGEAGE:
      let data = state.info;
      data.age = action.age;
      return {
        info: {...data}
      }
  
    case actionType.CHNAGENAME:
      let data1 = state.info;
      data1.name = action.name;
      return {
        info: {...data1}
      }
  
    default:
      return state
  }
}

export default userReducer